<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
  <title>AsynRecordControl</title>
</head>
<body>
<h1 style="text-align: center;">How to use an ASYN record
to communicate with a message-based instrument </h1>
<br>
<br>
Step-by-step example of how I set up simple instrument control
using only an ASYN record. The instrument may be connected to a
local serial port, a USB/Serial adapter, a LAN/Serial adapter, a
network port (raw TCP or
VXI-11), a local GPIB interface or a LAN/GPIB adapter.<br>
<ol>
  <li>Create a new application<br>
    <span style="font-family: monospace; font-weight: bold;">mkdir
serialTest</span><br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">cd
serialTest</span><br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">/usr/local/epics/R3.14.11/bin/darwin-x86/makeBaseApp.pl
-l</span><br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">/usr/local/epics/R3.14.11/bin/darwin-x86/makeBaseApp.pl
-t
ioc serialTest</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">/usr/local/epics/R3.14.11/bin/darwin-x86/makeBaseApp.pl
-i
-t ioc serialTest</span><br>
    <br>
  </li>
  <li>Add ASYN support.<br>
Edit configure/RELEASE and add a line specifying the path to your ASYN
installation<br>
    <span style="font-family: monospace; font-weight: bold;">ASYN=</span><span
 style="font-family: monospace; font-weight: bold;">/usr/local/epics/R3.14.11</span><span
 style="font-family: monospace; font-weight: bold;">/modules/soft/asyn</span><br>
    <br>
Edit serialTestApp/src/Makefile and add two lines. It should be
apparent from the template where these lines are to be placed:<br>
    <span style="font-family: monospace; font-weight: bold;">serialTest_DBD
+=
drvVxi11.dbd</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">serialTest_LIBS
+=
asyn</span><br>
For a local serial port or a USB/Serial adpater, replace <span
 style="font-family: monospace; font-weight: bold;">drvVxi11</span>
with <span style="font-family: monospace; font-weight: bold;">drvAsynSerialPort.<br>
    </span>For a 'telnet' style network port (instrument or
LAN/Serial adapter), replace <span
 style="font-family: monospace; font-weight: bold;">drvVxi11</span>
with <span style="font-family: monospace; font-weight: bold;">drvAsynIPPort.</span><br>
    <br>
Edit serialTestApp/Db/Makefile and add a line:<br>
    <span style="font-family: monospace; font-weight: bold;">DB_INSTALLS
+=
$(ASYN)/db/asynRecord.db</span><br>
    <br>
Edit iocBoot/iocSerialTest/st.cmd and add lines to configure the
serial, GPIB or network port and to load an ASYN record. Here's a
complete
st.cmd file showing how things should look when you're finished.
You will, of course, have to substitute the IP address of your GPIB/LAN
adapter and the address of your GPIB device. You'll likely want
to choose a different value for the PV name prefix macro (P) as
well. The IMAX and OMAX values should be large enough to handle
the longest messages you expect.<br>
    <br>
    <span style="font-family: monospace; font-weight: bold;">#!../../bin/darwin-x86/serialTest</span><br
 style="font-family: monospace; font-weight: bold;">
    <br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">&lt;
envPaths</span><br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">cd ${TOP}</span><br
 style="font-family: monospace; font-weight: bold;">
    <br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">##
Register all support components</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">dbLoadDatabase("dbd/serialTest.dbd",0,0)</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">serialTest_registerRecordDeviceDriver(pdbbase)</span><br
 style="font-family: monospace; font-weight: bold;">
    <br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">##
Configure devices</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">vxi11Configure("L0","164.54.8.129",0,0.0,"gpib0",0,0)</span><br
 style="font-family: monospace; font-weight: bold;">
    <br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">## Load
record instances</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">dbLoadRecords("db/asynRecord.db","P=norum:,R=asyn,PORT=L0,ADDR=24,IMAX=100,OMAX=100")</span><br
 style="font-family: monospace; font-weight: bold;">
    <br style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">cd
${TOP}/iocBoot/${IOC}</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">iocInit()</span><br>
    <br>
If you are using a LAN/Serial adapter or network attached device which
uses a raw TCP ('telnet' style) connection you would replace the <span
 style="font-family: monospace; font-weight: bold;">vxi11Configure</span>
command with a line like:<br>
    <span style="font-family: monospace; font-weight: bold;">drvAsynIPPortConfigure("L0","192.168.0.23:4001",0,0,0)</span><br>
If you are using a local serial port or USB/Serial adapter replace the <span
 style="font-family: monospace; font-weight: bold;">vxi11Configure</span>
command with something like:<br>
    <span style="font-family: monospace; font-weight: bold;">drvAsynSerialPortConfigure("L0","/dev/tty.PL2303-000013FA",0,0,0)</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">asynSetOption("L0",
-1, "baud", "9600")</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">asynSetOption("L0",
-1, "bits", "8")</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">asynSetOption("L0",
-1, "parity", "none")</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">asynSetOption("L0",
-1, "stop", "1")</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">asynSetOption("L0",
-1, "clocal", "Y")<br>
asynSetOption("L0", -1, "crtscts", "Y")</span><br>
    <br>
  </li>
  <li>Build the application (run <span
 style="font-family: monospace; font-weight: bold;">make</span> from
the application top directory).<br>
    <br>
  </li>
  <li>Start the IOC<br>
    <span style="font-family: monospace; font-weight: bold;">cd
iocBoot/iocserialTest</span><br
 style="font-family: monospace; font-weight: bold;">
    <span style="font-family: monospace; font-weight: bold;">../../bin/darwin-x86/serialTest
st.cmd</span><br>
    <br>
  </li>
  <li>From another window, start MEDM. Make sure that the P and R
macro values match those from st.cmd.<br>
    <span style="font-family: monospace; font-weight: bold;">medm -x
-macro "P=norum:,R=asyn"
/usr/local/epics/R3.14.11/modules/soft/asyn/medm/asynRecord.adl </span><br>
    <br>
You should see something like the window shown below. I've made a
few changes to the original values including increasing the trace I/O
truncate size to 100 characters, enabling the traceIOEscape display and
turning on traceIODriver debugging.<br>
    <br>
    <img style="width: 442px; height: 487px;" alt="AsynRecordWindow.png"
 src="AsynRecordWindow.png"><br>
    <br>
Click on the 'More...' button and bring up the "asynOctet Interface
I/O" window. I've made some changes here as well &#8211; I've selected
Binary input format and increased the requested input length to
100. If your device messages are 40 characters or less you don't
have to make this change. If you're using a non-GPIB device you
probably need to specify appropriate input and output terminator
characters.<br>
    <br>
    <img style="width: 442px; height: 372px;" alt="AsynOctet.png"
 src="AsynOctet.png"><br>
    <br>
Try entering some commands. A good one to start with is the SCPI
Device Identification (*IDN?) command. You can see why I had to
arrange for reply messages longer than the default 40 characters!<br>
    <br>
    <img style="width: 442px; height: 372px;" alt="AynsOctetIDN.png"
 src="AsynOctetIDN.png"><br>
    <br>
The readback display is truncated. Since I have traceIODriver
enabled I can see the entire message in the IOC console window:<br>
<pre>    2007/09/20 09:01:15.998 L0 24 vxiWrite
    *IDN?
    2007/09/20 09:01:16.009 L0 24 vxiRead
    KEITHLEY INSTRUMENTS INC.,MODEL 2400,1163289,C30   Mar 17 2006 09:29:29/A02  /K/J\n
</pre>
</li>
  <li>If your requirements are modest, you might be done. The
ASYN
record may be adequate for your application. If not, you should
investigate the <a
 href="http://www.aps.anl.gov/epics/modules/soft/asyn/HowToDoSerial_StreamDevice.html">Streams</a>
package or <a
 href="http://www.aps.anl.gov/epics/modules/soft/asyn/R4-14/HowToDoSerial/tutorial.pdf">devGpib</a>
for writing support for your
instrument.<br>
  </li>
</ol>
<br>
</body>
</html>
